{extend name="../public/header" /}
{block name="body"}
<body>
{include file="../public/common" /}
<fieldset class="layui-elem-field site-demo-button" style="padding:10px;">
	<div class="layui-row">
		<!--  -->
		<form id="form1" class="layui-form layui-form-pane" action="{:url('')}">
			<section class="panel panel-padding">
				<div class="layui-form-item">
					<label class="layui-form-label">名称</label>
					<div class="layui-input-inline">
						<input type="text" name="nname" value="{$info.nname|default=''}" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">等级</label>
					<div class="layui-input-inline">
						<input type="text" name="nlv" value="{$info.nlv|default=''}" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">职称</label>
					<div class="layui-input-inline">
						<input type="text" name="nickname" value="{$info.nickname|default=''}" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">介绍</label>
					<div class="layui-input-inline">
						<textarea name="ninfo" placeholder="请输入介绍" class="layui-textarea">{$info.ninfo|default=''}</textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">性别</label>
					<div class="layui-input-inline">
						<input type="radio" name="nsex" {eq name="$info.nsex" value="男"}checked{/eq} title="男" value="男" checked />
						<input type="radio" name="nsex" {eq name="$info.nsex" value="女"}checked{/eq} title="女" value="女"/>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">模板</label>
					<div class="layui-input-inline">
						<input type="text" name="muban" value="{$info.muban|default=''}" class="layui-input">
					</div>
				</div>
				<!-- / -->
				<fieldset class="layui-elem-field">
					<legend>任务配置</legend>
					<div class="layui-field-box">
						<div class="layui-row" id="taskid">
							<div class="layui-form-item">
								<label class="layui-form-label">Task</label>
								<button class="layui-btn ajax-getTask" data-url="{:url('getTaskList')}" type="button">新增</button>
							</div>
							{foreach name='info.task_list' item='vo'}
							<div class="layui-form-item">
								<label class="layui-form-label">ID</label>
								<div class="layui-input-inline">
									<input name="taskid[{$key}][id]" value="{$vo.id}" placeholder="请输入" class="layui-input " type="text">
								</div>
								<label class="layui-form-label">名称</label>
								<div class="layui-input-inline" style='width: 500px;'>
									<input name="taskid[{$key}][name]" value="{$vo.name}" placeholder="请输入" class="layui-input " type="text">
								</div>
								<button class="layui-btn layui-btn-danger" onclick="delNumTask(this)" type="button">-</button>
							</div>
							{/foreach}
						</div>
					</div>
				</fieldset>
				<!-- / -->

				<div class="layui-input-block">
					<input type="hidden" name="id" type="hidden" value="{$info.id|default=''}">
					<button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</section>
		</form>
		<!--  -->
	</div>
</fieldset>
</body>
{/block}
{block name="script"}
<script>
layui.use(['jquery','form','laydate','upload','element'], function(){
	var $ = layui.jquery
	,laydate = layui.laydate
	,upload = layui.upload
	,element = layui.element
	,form = layui.form;

	$('.ajax-getTask').on('click',function(){
		var obj = $(this);
		var url = obj.data('url');
		var title = obj.data('title');

		layer.open({
			type: 2,
			title: title,
			shadeClose: true, //是否点击遮罩关闭 默认：false
			maxmin: false, //开启最大化最小化按钮 默认：false
			area: ['500px', '400px'],
			content: url,
			btn: ['确定', '取消'],
			yes: function (index, layero) {
				var n = $(layero).find('iframe')[0];
				var objb = $(n).contents().find("select[name='task_id'] option:selected");
				var task_id = $(objb).val();
				var text = $(objb).text();

				console.log('id',task_id);
				console.log('name',text);

				addNpc(task_id,text);

				layer.close(index);
			},
			btn2: function (index, layero) {
				layer.close(index);
			},
			cancel: function () {
				//右上角关闭回调
				return true //开启该代码可禁止点击该按钮关闭
			}
		})
	});

	form.render();
});
</script>
<script>
	var num_task = "{$num_task|default='1'}";

	layui.use(['jquery','form'], function(){
		var $ = layui.jquery
				,form = layui.form;

		window.addNpc = function(id,name) {
			console.log('num_task',num_task);
			$("#taskid").append(
					"<div class='layui-form-item'>" +
					"<label class='layui-form-label'>ID</label>" +
					"<div class='layui-input-inline'>" +
					"<input type='text' name='taskid["+num_task+"][id]' value='"+id+"' placeholder='请输入' class='layui-input '>" +
					"</div>" +
					"<label class='layui-form-label'>名称</label>" +
					"<div class='layui-input-inline' style='width: 500px;'>" +
					"<input type='text' name='taskid["+num_task+"][name]' value='"+name+"' placeholder='请输入' class='layui-input '>" +
					"</div>" +
					"<button class='layui-btn layui-btn-danger'  onclick='delNumTask(this)' type='button'>-</button>" +
					"</div>");
			num_task++;
		}
	});

	function delNumTask(obj) {
		var $= layui.jquery;
		$(obj).parent().remove();
		num_task--;
	}
</script>
{/block}